package com.zhongxiangspace.tools;


import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.IOException;
import java.io.StringReader;

public class IKAnalyzerTools {
   static String text = "小孩不听话怎么办？吃东坡肉啊！";

    public static void main(String[] args) throws IOException {
        //创建分词对象
        Analyzer anal =  new IKAnalyzer();
        StringReader reader = new StringReader(text);
        //分词
        TokenStream ts = anal.tokenStream("", reader);
        CharTermAttribute term = ts.getAttribute(CharTermAttribute.class);
        System.out.println(term.toString()+" ");
        reader.close();
        System.out.println();
    }
}
